package com.cfs.svcimpl.bz;

import java.util.List;

import com.cfs.dao.bz.NoticeDao;
import com.cfs.po.bz.Notice;
import com.cfs.svc.bz.NoticeService;
import com.cfs.vo.Condition;
import com.cfs.vo.Pager;
import com.cfs.vo.Res;

public class NoticeServiceImpl implements NoticeService {

	private NoticeDao dao;	
	
	public NoticeDao getDao() {
		return dao;
	}

	public void setDao(NoticeDao dao) {
		this.dao = dao;
	}

	public List<Notice> list(Condition c) {
		return dao.list(c);
	}

	public Notice get(Long id) {
		return dao.get(id);
	}

	public Long add(Notice n) {		
		Long num = dao.insert(n);
		System.out.println("RETURN Notice NUM: " + num + " ID:" + n.getId());
		dao.release(n);
		return  n.getId();
	}

	public Long check(Notice n) {
		return dao.check(n);
	}

	public Res<Notice> listP(Condition c) {
		Res<Notice> res = new Res<Notice>();
		try{
			Pager p = c.getP() == null ? new Pager() : c.getP();
			p.resetTotalR(dao.queryRows(c));
			List<Notice> list = dao.list(c);

			res.setP(p);
			res.setList(list);

		}catch(Exception e){
			res.setCode(-1);
			res.setMsg(e.getLocalizedMessage());
			e.printStackTrace();
		}
		
		return res;
	}

}
